#include <iostream>
#include "SimpleLinkListWithoutHeadNode.h"

using namespace std;

template <class ElemType>
void Show(const ElemType &e)
{
    cout << e << " ";
}

int main()
{
    char c = '0';
    SimpleLinkListWithoutHeadNode<double> la, lb;
    double e;
    int position;

    while (c != '7')
    {
        cout << '\n'
             << "1. 生成线性表.";
        cout << '\n'
             << "2. 显示线性表.";
        cout << '\n'
             << "3. 检索元素.";
        cout << '\n'
             << "4. 设置元素值.";
        cout << '\n'
             << "5. 删除元素.";
        cout << '\n'
             << "6. 插入元素.";
        cout << '\n'
             << "7. 退出.";
        cout << '\n'
             << "选择功能(1~7):";
        cin >> c;
        switch (c)
        {
        case '1':
            cout << '\n'
                 << "输入e（e=0时退出）:";
            cin >> e;
            while (e != 0)
            {
                la.Insert(la.Length() + 1, e);
                cin >> e;
            }
            break;
        case '2':
            // lb = la;
            la.Traverse(Show<double>);
            break;
        case '3':
            cout << '\n'
                 << "输入元素位置:";
            cin >> position;
            if (!la.GetElem(position, e))
                cout << "元素不存储." << '\n';
            else
                cout << "元素:" << e << '\n';
            break;
        case '4':
            cout << '\n'
                 << "输入元素位置:";
            cin >> position;
            cout << '\n'
                 << "输入元素值:";
            cin >> e;
            if (!la.SetElem(position, e))
                cout << "位置范围错.";
            else
                cout << "设置成功" << '\n';
            break;
        case '5':
            cout << '\n'
                 << "输入位置:";
            cin >> position;
            if (!la.Delete(position, e))
                cout << "位置范围错.";
            else
                cout << "被删除的元素值" << e << '\n';
            break;
        case '6':
            cout << '\n'
                 << "输入位置:";
            cin >> position;
            cout << '\n'
                 << "输入元素值:";
            cin >> e;
            if (!la.Insert(position, e))
                cout << "位置范围错." << '\n';
            else
                cout << "成功插入:" << e << '\n';
            break;
        default:
            break;
        }
    }

    return 0;
}